package com.briup.oagg.dataset.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.dataset.service.IDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 数据集数据信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "6.数据集数据管理")
@RequestMapping("/data")
@RestController
public class DataController {
    @Autowired
    private IDataService service;

    @ApiOperation(value = "导入数据",notes = "导入数据为.cvs格式的数据")
    @PostMapping("/import")
    public Response<String> importData(@RequestPart MultipartFile dataFile,
                                       @RequestParam String datasetId){
        service.importData(dataFile,datasetId);
        return Response.success();
    }

    @ApiOperation("删除数据")
    @DeleteMapping("/{datasetId}/{dataId}")
    public Response deleteById(@PathVariable String datasetId,@PathVariable String dataId){
        service.deleteById(datasetId,dataId);
        return Response.success();
    }

    @ApiOperation("分页查询指定数据集中数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "datasetId",value = "数据集编号",required = true),
            @ApiImplicitParam(name = "pageNum", value = "当前页码",defaultValue = "1",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",defaultValue = "5",required = true,dataTypeClass = Integer.class)
    })
    @GetMapping
    public Response<Page<Map>> findByPage(@RequestParam String datasetId,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        Page<Map> page = service.findByPage(datasetId, pageNum, pageSize);
        return Response.success(page);
    }

    @ApiOperation("查询指定数据集所有数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "datasetId",value = "数据集编号")
    })
    @GetMapping("/{datasetId}")
    public Response<List<Map>> selectByDatasetId(@PathVariable String datasetId){
        List<Map> list = service.findByDatasetId(datasetId);
        return Response.success(list);
    }
}
